package com.yicong.ants.ui.coin;

import android.os.Bundle;
import android.util.Pair;

import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentPagerAdapter;

import com.cchao.simplelib.ui.activity.BaseTitleBarActivity;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.databinding.DelayTransferTabActivityBinding;

import java.util.ArrayList;
import java.util.List;

/**
 *
 */
public class DelayTransferActivity extends BaseTitleBarActivity<DelayTransferTabActivityBinding> {
    List<Pair<String, Fragment>> mContent;

    @Override
    protected int getLayout() {
        return R.layout.delay_transfer_tab_activity;
    }

    @Override
    protected void initEventAndData() {
        setTitleText("延迟转赠记录");
//        StatusBarUtil.setWhiteBgDarkText(getWindow());
//        findViewById(R.id.general_title_root).setBackgroundResource(R.color.white);
        mContent = new ArrayList<>();
        //0=from_uid 自己转给别人；1=to_uid 别人转给自己
        mContent.add(Pair.create("转赠好友", getFragments("0")));
        mContent.add(Pair.create("收到转赠", getFragments("1")));
        initViewPager();
    }

    @Override
    protected void onLoadData() {
    }

    private static Fragment getFragments(String category) {
        Fragment fragment = new DelayTransferListFragment();
        Bundle bundle = new Bundle();
        bundle.putString(Constants.Extra.Category, category);
        fragment.setArguments(bundle);
        return fragment;
    }

    private void initViewPager() {
        mDataBind.viewPage.setAdapter(new FragmentPagerAdapter(getSupportFragmentManager()) {
            @Override
            public Fragment getItem(int i) {
                return mContent.get(i).second;
            }

            @Override
            public int getCount() {
                return mContent.size();
            }

            @Nullable
            @Override
            public CharSequence getPageTitle(int position) {
                return mContent.get(position).first;
            }
        });
        mDataBind.tabLayout.setViewPager(mDataBind.viewPage);
        mDataBind.viewPage.setOffscreenPageLimit(mContent.size());
        mDataBind.tabLayout.onPageSelected(0);
    }
}
